/**
    @project {
        "templateId": "org.helgoboss.custom",
        "version": "0.1-SNAPSHOT",
        "dependencies": [
            "org.scala-lang:scala-library:2.9.0-1",
            "org.helgoboss:scala-additions:0.1-SNAPSHOT",
            "org.slf4j:slf4j-api:1.6.0"
        ]
    }
*/

package org.helgoboss.scala_slf4j

import org.helgoboss.scala_additions.Logger
import org.slf4j.LoggerFactory

trait Slf4jLogger extends Logger {
    def slf4jLoggerClass: Class[_]
    
    private val slf4jLogger = LoggerFactory.getLogger(slf4jLoggerClass)

    def debug(message: => AnyRef) {
        if (slf4jLogger.isDebugEnabled)
            slf4jLogger.debug(message.toString)
    }
    
    def debug(message: => AnyRef, exception: => Throwable) {
        if (slf4jLogger.isDebugEnabled)
            slf4jLogger.debug(message.toString, exception)
    }
    
    def info(message: => AnyRef) {
        if (slf4jLogger.isInfoEnabled)
            slf4jLogger.info(message.toString)
    }
    
    def info(message: => AnyRef, exception: => Throwable) {
        if (slf4jLogger.isInfoEnabled)
            slf4jLogger.info(message.toString, exception)
    }
    
    def warn(message: => AnyRef) {
        if (slf4jLogger.isWarnEnabled)
            slf4jLogger.warn(message.toString.toString)
    }
    
    def warn(message: => AnyRef, exception: => Throwable) {
        if (slf4jLogger.isWarnEnabled)
            slf4jLogger.warn(message.toString, exception)
    }
    
    def error(message: => AnyRef) {
        if (slf4jLogger.isErrorEnabled)
            slf4jLogger.error(message.toString)
    }
    
    def error(message: => AnyRef, exception: => Throwable) {
        if (slf4jLogger.isErrorEnabled)
            slf4jLogger.error(message.toString, exception)
    }
    
    def trace(message: => AnyRef) {
        if (slf4jLogger.isTraceEnabled)
            slf4jLogger.trace(message.toString)
    }
    
    def trace(message: => AnyRef, exception: => Throwable) {
        if (slf4jLogger.isTraceEnabled)
            slf4jLogger.trace(message.toString, exception)
    }
}

trait Slf4jLogging {
    lazy val log = new Slf4jLogger {
        lazy val slf4jLoggerClass = Slf4jLogging.this.getClass
    }
}